package com.itheima.algorithm.stack;

/**
 * @author: TylerZhong
 * @description:
 */
public class E04Leetcode232 {

    private ArrayStack<Integer> a1 = new ArrayStack<>(100);
    private ArrayStack<Integer> a2 = new ArrayStack<>(100);
    public void push(int x) {
        a1.push(x);
    }

    public int pop() {
        if (a2.isEmpty()) {
            while (!a1.isEmpty()) {
                a2.push(a1.pop());
            }
        }
        return a2.pop();
    }

    public int peek() {
        if (a2.isEmpty()) {
            while (!a1.isEmpty()) {
                a2.push(a1.pop());
            }
        }
        return a2.peek();
    }

    public boolean empty() {
        return a1.isEmpty() && a2.isEmpty();
    }
}
